<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>JS Unit Tests for Namespace: icodeon.rte</title>
    <!--  script language="Javascript" src="../jsunit/app/jsUnitCore.js"></script-->
	<script language="Javascript" src="../icodeon.cocd.js"></script>
	<script language="Javascript" src="../icodeon.rte.js"></script>
	<script language="Javascript" src="../icodeon.xml.js"></script>
    <script language="Javascript"  src="./icodeon.jsunit.js"></script>

    <script language="Javascript">
        function testInheritance(){
        	try{
           		var obj_Adapter = new  icodeon.rte.Adapter();
           		var obj_Adapter1p2 = new icodeon.rte.Adapter1p2();
           		assertNotEquals("testInheritance", obj_Adapter.toString(), obj_Adapter1p2.toString());
           	}
           	catch(obj_Error){
           		fail(obj_Error);
           	}
        }
        
        function testDefinitions(){
        
            try{
           		var obj_Adapter = new icodeon.rte.Adapter();
           		var str_CmiName = "completion_status";
           		var obj_Definition = obj_Adapter.definitions[str_CmiName];
           		assertNotNull("obj_Adapter.definitions[str_CmiName]", obj_Definition);
           		obj_Definition.validateCmiValue("completed");
           		var str_CocdValue = obj_Definition.toCocdValue("completed");
           		assertEquals("obj_Definition.toCocdValue(\"completed\")", "completed", str_CocdValue);
			}
           	catch(obj_Error){
           		fail(obj_Error.message);
           	}
        }
        
        function testDataTransferMethods1p2(){
        	try{
           		var API = new icodeon.rte.Adapter1p2();
           		var str_Result = API.LMSInitialize("");
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "0", str_Result);
           		
           		// cmi._version is read only
           		str_Result = API.LMSGetValue("cmi._version");
           		assertEquals("API.LMSGetValue(\"cmi._version\")", "1.0", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "0", str_Result);
           		str_Result = API.LMSGetValue("cmi.entry._version");
           		assertEquals("API.LMSGetValue(\"cmi.entry._version\")", "", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "301", str_Result);
           		
           		// cmi.core.credit is read only
           		str_Result = API.LMSGetValue("cmi.core.credit");
           		assertEquals("API.LMSGetValue(\"cmi.core.credit\")", "credit", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "0", str_Result);
           		var str_Diagnostic = API.LMSGetDiagnostic(str_Result);
           		assertEquals("API.GetDiagnostic(str_Result)", "", str_Diagnostic);
           		str_Result = API.LMSSetValue("cmi.core.credit","resume");
           		assertEquals("API.LMSSetValue(\"cmi.core.credit\",\"resume\")", "false", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "403", str_Result);//read only
           		
           		// cmi.core.entry is read only
           		str_Result = API.LMSGetValue("cmi.core.entry");
           		assertEquals("API.LMSGetValue(\"cmi.core.entry\")", "ab-initio", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "0", str_Result);
           		var str_Diagnostic = API.LMSGetDiagnostic(str_Result);
           		assertEquals("API.GetDiagnostic(str_Result)", "", str_Diagnostic);
           		str_Result = API.LMSSetValue("cmi.core.entry","resume");
           		assertEquals("API.LMSSetValue(\"cmi.core.entry\",\"resume\")", "false", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "403", str_Result);//read only
           		
           		// cmi.core.exit is write only, with controlled vocabulary
           		str_Result = API.LMSSetValue("cmi.core.exit","suspend");
           		assertEquals("API.LMSSetValue(\"cmi.core.exit\",\"suspend\")", "true", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "0", str_Result);
           		str_Result = API.LMSGetValue("cmi.core.exit");
           		assertEquals("API.LMSGetValue(\"cmi.core.exit\")", "", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "404", str_Result);// write only
           		str_Result = API.LMSSetValue("cmi.core.exit","illegal value");
           		assertEquals("API.LMSSetValue(\"cmi.core.exit\",\"illegal value\")", "false", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "406", str_Result);// Data Model Element Type Mismatch
           		
           		// cmi.launch_data is read only
           		str_Result = API.LMSGetValue("cmi.launch_data");
           		assertEquals("API.LMSGetValue(\"cmi.launch_data\")", "", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "0", str_Result);
           		var str_Diagnostic = API.LMSGetDiagnostic(str_Result);
           		assertEquals("API.GetDiagnostic(str_Result)", "", str_Diagnostic);
           		str_Result = API.LMSSetValue("cmi.launch_data","resume");
           		assertEquals("API.LMSSetValue(\"cmi.launch_data\",\"resume\")", "false", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "403", str_Result);//read only
           		
           		// cmi.launch_data is read/write
           		str_Result = API.LMSGetValue("cmi.suspend_data");
           		assertEquals("API.LMSGetValue(\"cmi.suspend_data\")", "", str_Result);
           		//str_Result = API.LMSGetLastError();
           		//assertEquals("API.LMSGetLastError()", "0", str_Result);
           		//var str_Diagnostic = API.LMSGetDiagnostic(str_Result);
           		//assertEquals("API.GetDiagnostic(str_Result)", "", str_Diagnostic);
           		str_Result = API.LMSSetValue("cmi.suspend_data","resume");
           		assertEquals("API.LMSSetValue(\"cmi.suspend_data\",\"resume\")", "true", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "0", str_Result);//read only
           		
           		// cmi.core.lesson_mode is read only
           		str_Result = API.LMSGetValue("cmi.core.lesson_mode");
           		assertEquals("API.LMSGetValue(\"cmi.core.lesson_mode\")", "normal", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "0", str_Result);
           		var str_Diagnostic = API.LMSGetDiagnostic(str_Result);
           		assertEquals("API.GetDiagnostic(str_Result)", "", str_Diagnostic);
           		str_Result = API.LMSSetValue("cmi.core.lesson_mode","resume");
           		assertEquals("API.LMSSetValue(\"cmi.core.lesson_mode\",\"resume\")", "false", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "403", str_Result);//read only
           		
           		/*
           		// cmi.learner_preference
           		str_Result = API.LMSGetValue("cmi.learner_preference._children");
           		assertEquals("API.LMSGetValue(\"cmi.learner_preference._children\")", "audio_captioning,audio_level,delivery_speed,language", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "0", str_Result);

           		// cmi.learner_preference.audio_level
           		str_Result = API.LMSGetValue("cmi.learner_preference.audio_level");
           		assertEquals("API.LMSGetValue(\"cmi.learner_preference.audio_level\")", "1", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "0", str_Result);
           		*/
           		
           		// cmi.core.score
           		str_Result = API.LMSGetValue("cmi.core.score._children");
           		assertEquals("API.LMSGetValue(\"cmi.core.score._children\")", "max,min,raw,scaled", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "0", str_Result);
           		
          		str_Result = API.LMSGetValue("cmi.core.score.min");
           		assertEquals("API.LMSGetValue(\"cmi.core.score.min\")", "", str_Result);
           		//str_Result = API.LMSGetLastError();
           		//assertEquals("API.LMSGetLastError()", "0", str_Result);
           		
           		str_Result = API.LMSSetValue("cmi.core.score.min","resume");
           		assertEquals("API.LMSSetValue(\"cmi.core.score.min\",\"resume\")", "false", str_Result);
           		//str_Result = API.LMSGetLastError();
           		//assertEquals("API.LMSGetLastError()", "405", str_Result);//incorrect data type

           		str_Result = API.LMSSetValue("cmi.core.score.min","0");
           		assertEquals("API.LMSSetValue(\"cmi.core.score.min\",\"0\")", "true", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "0", str_Result);//incorrect data type
           	}
          	catch(obj_Error){
           		fail(obj_Error.message);
           	}	
        }
        
        function testSessionMethods1p2(){
        	try{

           		var API = new icodeon.rte.Adapter1p2();
           		
           		// Terminate
           		var str_Result = API.LMSFinish("");
           		assertEquals("API.LMSFinish('')", "false", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "112", str_Result);
           		var str_Msg = API.LMSGetErrorString(str_Result);
           		assertNotNull("API.LMSGetErrorString(str_Result)", str_Msg);
           		str_Msg = API.LMSGetDiagnostic(str_Result);
           		assertNotNull("API.LMSGetDiagnostic(str_Result)", str_Msg);
           		
           		// Commit
           		str_Result = API.LMSCommit("");
           		assertEquals("API.LMSCommit('')", "false", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "142", str_Result);
           		var str_Msg = API.LMSGetErrorString(str_Result);
           		assertNotNull("API.LMSGetErrorString(str_Result)", str_Msg);
           		str_Msg = API.LMSGetDiagnostic(str_Result);
           		assertNotNull("API.LMSGetDiagnostic(str_Result)", str_Msg);
           		
        		// Initialize	
           		str_Result = API.LMSInitialize();
           		assertEquals("API.LMSInitialize()", "false", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "201", str_Result);
           		str_Msg = API.LMSGetErrorString(str_Result);
           		assertNotNull("API.LMSGetErrorString(str_Result)", str_Msg);
           		str_Msg = API.LMSGetDiagnostic(str_Result);
           		assertNotNull("API.LMSGetDiagnostic(str_Result)", str_Msg);
           		str_Result = API.LMSInitialize("");
           		assertEquals("API.LMSInitialize('')", "true", str_Result);
           		
           		// Commit
           		str_Result = API.LMSCommit();
           		assertEquals("API.LMSCommit()", "false", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "201", str_Result);
           		str_Result = API.LMSCommit("");
           		assertEquals("API.LMSCommit('')", "true", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "0", str_Result);
           		var str_Msg = API.LMSGetErrorString(str_Result);
           		assertNotNull("API.LMSGetErrorString(str_Result)", str_Msg);
           		str_Msg = API.LMSGetDiagnostic(str_Result);
           		assertNotNull("API.LMSGetDiagnostic(str_Result)", str_Msg);
           		
           		// Finish
           		str_Result = API.LMSFinish();
           		assertEquals("API.LMSFinish()", "false", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "201", str_Result);
           		str_Result = API.LMSFinish("");
           		assertEquals("API.LMSFinish()('')", "true", str_Result);
           		str_Result = API.LMSGetLastError();
           		assertEquals("API.LMSGetLastError()", "0", str_Result);
           		var str_Msg = API.LMSGetErrorString(str_Result);
           		assertNotNull("API.LMSGetErrorString(str_Result)", str_Msg);
           		str_Msg = API.LMSGetDiagnostic(str_Result);
           		assertNotNull("API.LMSGetDiagnostic(str_Result)", str_Msg);
           	}
           	catch(obj_Error){
           		fail(obj_Error.message);
           	}
        }
    </script>
</head>
<body>
<h2>JS Unit Tests for Namespace: icodeon.rte for SCORM 1.2</h2>
<form>
<input type="button" onclick="testDefinitions();" value="Test Definitions"/>&nbsp;
<input type="button" onclick="testSessionMethods1p2();" value="Test Session Methods 1.2"/>&nbsp;
<input type="button" onclick="testDataTransferMethods1p2();" value="Test Data Transfer Methods 1.2"/>&nbsp;
</form>
<div id="testLog"></div>
</body>
</html>
